import json
import common
import requests
from main import main

def send(
    route,
    json_content=None,
    post=True,
    ip = common.args.ClientUIBackendIP,
    port = common.args.ClientUIBackendPort
):
    url = f"http://{ip}:{port}"
    url = f"{url}{route}"
    if post:
        resp = requests.post(url,json=json_content)
    else:
        resp = requests.get(url)
    resp_content = resp.content.decode("utf-8")
    return resp_content

# OK
r = send("/sign_in",{
    "account_private_key":"1eb8e2955a7c928c1d5b4568c0ea42a3d3f31968f49efc40a1351e3b255f00fe"
})
print(r)

#
r = send("/acct_address",post=False)
print(r)

# # OK
# ip = "172.16.197.130"
# port = 8888
# r = send("/acct_address",post=False,ip=ip,port=port)
# print(r)

# TODO 发现处理完安全通道后，没有把相应对象清理,之后再说了

# OK
r = send("/DU_send_registration_request",{
    # "target_ip":"172.16.197.130"
    "target_ip":"192.168.254.132"
})
print(r)

# import time 

# while True:
#     time.sleep(1)
